import ccclass = cc._decorator.ccclass;
import property = cc._decorator.property;
import WeaponTalent from "../popups/WeaponTalent";
import LocalStorage from "../../framework/utils/LocalStorage";
import Component from "../../framework/Component";


@ccclass 
export default class WeaponItem extends Component {

    @property(cc.Sprite)
    private icon: cc.Sprite = null;
    @property(cc.Label)
    private playerName: cc.Label = null;
    @property(cc.Label)
    private weaponName: cc.Label = null;
    @property(cc.Label)
    private talentName: cc.Label = null;
    @property(cc.Label)
    private curTalentLv: cc.Label = null;
    @property(cc.Label)
    private lastTalentLv: cc.Label = null;
    @property(cc.Node)
    private clickBtn: cc.Node = null;
    private data = null;
    public setInfo(data) {
        this.data = data;
        this.setClickListener(this.clickBtn,this.onClickBtn);
        cc.log('data', data);
        var weaponData: any = LocalStorage.getObj("weaponLv");
        for (let i = 0; i < weaponData.length; i++) {
            if (Number(weaponData[i]['id']) == Number(data["id"])) {
                this.playerName.string = data["name"];
                this.weaponName.string = "+" + (Number(weaponData[i]["lv"]) + 1) + "的" + data["name"];
                this.curTalentLv.string = "Lv" + weaponData[i]["lv"];
                this.lastTalentLv.string = "Lv" + (Number(weaponData[i]["lv"]) + 1);
                this.talentName.string = "天赋·" + data["skill_name"];
                this.clickBtn.active = true;
                return;
            }
            else {
                this.playerName.string = "????";
                this.weaponName.string = "????";
                this.curTalentLv.string = "????";
                this.lastTalentLv.string = "???";
                this.talentName.string = "???";
                this.clickBtn.active = false;
            }
        }
    }
    public onClickBtn(e: cc.Event.EventTouch) {
        WeaponTalent.sendData(this.data);
    }
}
